package com.lelaohui.net;

import android.app.Application;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.content.LocalBroadcastManager;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;

import com.lelaohui.net.netmanager.NetManager;
import com.lelaohui.net.netmanager.NetRequestManager;
import com.lelaohui.net.netmanager.ServerNetRequestManager;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Response;

/**
 * Created by T460p on 2017/3/15.
 */

public class LeLaoHuiApplication extends Application {
    public static final String PROMOT_ACTION = "com.lelaohui.promot.action";
    private LocalBroadcastManager localBroadcastManager;
    public static final String PROMOT_KEY = "promotKey";
    public static final String TAG = "LeLaoHuiApplication";
    public static BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String message = intent.getStringExtra(PROMOT_KEY);
            if (TextUtils.isEmpty(message))
                Log.d(TAG, "broadcastReceiver111==" + message);
            return;
        }
    };

    @Override
    public void onCreate() {
        super.onCreate();
        localBroadcastManager = LocalBroadcastManager.getInstance(this);
        IntentFilter filter = new IntentFilter();
        filter.addAction(PROMOT_ACTION);
        localBroadcastManager.registerReceiver(broadcastReceiver, filter);
        NetRequestManager.getInstance().setContext(this);
        ServerNetRequestManager.getInstance().setContext(this);
//        NetManager.Config netCfg=new NetManager.Config();
//        netCfg.setCacheFile(getCacheDir());
////        netCfg.setInterceptor(new Interceptor() {
////            @Override
////            public Response intercept(Chain chain) throws IOException {
////                chain.
////                return null;
////            }
////        });
//        NetManager.NetManagerBuilder builder=new NetManager.NetManagerBuilder().buildConfig(netCfg);

    }

}
